package com.example.ui.other;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.example.huashangapp.R;


import com.example.ui.sharte.util.SRecommend;

public class FAQadapter extends BaseExpandableListAdapter{
	private LayoutInflater inflater;
	private ArrayList<SRecommend> list;
	public FAQadapter(Context mContext,ArrayList<SRecommend> list){
		inflater = LayoutInflater.from(mContext);
        this.list=list;
	}
	public ArrayList<SRecommend> getCcInfos() {
		return list;
	}

	public void setCcInfos(ArrayList<SRecommend> list) {
		this.list = list;
		if (list == null) {
			this.list = new ArrayList<SRecommend>();
		}
	}	
	class Holder{
    	
    	TextView textTitle;
    	TextView textContent;
    }

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public long getChildId(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return 0;
	}
	@Override
	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Holder holder = null;
		SRecommend cc=list.get(groupPosition);
		if(convertView == null){
			convertView = inflater.inflate(R.layout.faq_item2, null);
			holder = new Holder();       				
			holder.textContent = (TextView) convertView.findViewById(R.id.faq_i2tv);
        	convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }								
		holder.textContent.setText(cc.getContent());
		return convertView;
	}
	@Override
	public int getChildrenCount(int groupPosition) {
		// TODO Auto-generated method stub
//		return list.size();
		return 1;
	}
	@Override
	public Object getGroup(int groupPosition) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public int getGroupCount() {
		// TODO Auto-generated method stub
		return list.size();
	}
	@Override
	public long getGroupId(int groupPosition) {
		// TODO Auto-generated method stub
		return 0;
	}
	@Override
	public View getGroupView(int groupPosition, boolean isExpanded,
			View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Holder holder = null;
		SRecommend cc=list.get(groupPosition);
		if(convertView == null){
			convertView = inflater.inflate(R.layout.faq_item1, null);
			holder = new Holder();       				
			holder.textTitle=(TextView) convertView.findViewById(R.id.faq_i1tv);
        	convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }								
		holder.textTitle.setText(cc.getTitle());
		return convertView;
	}
	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return true;
	}
}
